<?php

/**
 *  套装效果图重新生成或保存
 */
function test_commit_taozhuang_saveimg($json)
{
	$id = get_jsonValue($json,"id") ;
	$img = new set_image() ;
	$ok = $img->createAndSave_Set($id) ;
	
	$ret = array() ;
	if ($ok == true)	$ret['ok'] = 1 ;
	else 				$ret['ok'] = 0 ;
	
	$test = new test_bk() ;
	$ret['value'] = $test->get_table_for_page(1 , 1 , false , "" , "taozhuang" , " where `sid` = '$id'") ;	
	return $ret ;
}


/**
 *  更新套装pos表中的某些字段
 */
function test_taozhuang_update_base_pos($json)
{
	$id = get_jsonValue($json,"id") ;
	$feild = get_jsonValue($json,"field") ;
	
	$update = "" ;
	foreach ($feild as $f)
	{
		$k = $f[0] ;
		$v = $f[1] ;
		if ($update == "")	$update = " `$k` = '$v' " ;
		else 				$update .= " , `$k` = '$v' " ;
	}
	
	sql_query("update `taozhuang_pos` set $update where `id` = '$id'") ;
	
	$ret = array() ;
	$ret['result'] = 1 ;
	return $ret ; 
}
/**
 *  套装贴图中层数的上下移动
 */
function test_taozhuang_pos_move($json)
{
	$id = get_jsonValue($json,"id") ;
	$type = get_jsonValue($json,"type") ;
	$one = sql_fetch_one("select `pos` , `tzid` , `father` from `taozhuang_pos` where `id` = '$id'") ;
	
	$pos = intval($one['pos']) ;
	$did = intval($one['tzid']) ;
	$ftr = intval($one['father']) ;
	
	if ($type > 0){
		$two = sql_fetch_one("select `id` , `pos` , `tzid` from `taozhuang_pos` where `tzid` = '$did' and `father` = '$ftr' and `pos` > '$pos' and `order` = 0 order by `pos` asc") ;
	}else{
		$two = sql_fetch_one("select `id` , `pos` , `tzid` from `taozhuang_pos` where `tzid` = '$did' and `father` = '$ftr' and `pos` < '$pos' and `order` = 0 order by `pos` desc") ;
	}
	
	$ret = array() ;
	if (is_array($two) && array_key_exists('pos', $two)){
		$two_id = intval($two['id']) ;
		$two_pos = intval($two['pos']) ;
		
		sql_query("update `taozhuang_pos` set `pos` = -1 			where `tzid` = '$did' and `pos` = '$pos'") ;
		sql_query("update `taozhuang_pos` set `pos` = '$pos' 		where `tzid` = '$did' and `pos` = '$two_pos'") ;
		sql_query("update `taozhuang_pos` set `pos` = '$two_pos' 	where `tzid` = '$did' and `pos` = '-1'") ;

		sql_query("update `taozhuang_pos` set `father` = '-1' 			where `tzid` = '$did' and `father` = '$pos'") ;
		sql_query("update `taozhuang_pos` set `father` = '$pos' 		where `tzid` = '$did' and `father` = '$two_pos'") ;
		sql_query("update `taozhuang_pos` set `father` = '$two_pos' 	where `tzid` = '$did' and `father` = '-1'") ;
		
		$ret['result'] = 1 ;
		$ret['change1_id'] = $id ;
		$ret['change1_val'] = $two_pos ;
		$ret['change2_id'] = $two_id ;
		$ret['change2_val'] = $pos ;
	}else{
		$ret['result'] = 0 ;
		$ret['message'] = "没有移动的必要" ;
	}
	return $ret ;
}

/**
 * 通过位置获取对应可以更换的家具
 */
function test_taozhuang_pos($json)
{
	$tzid = get_jsonValue($json,"id") ;
	$pos = get_jsonValue($json,"pos") ;

	$ret = array() ;
	$ret['tz_pos'] = test_get_tz_pos_for_where("`tzid` = $tzid and `pos` = $pos") ;
	return $ret ;	
}

/**
 *  某个套装另存为
 */
function test_taozhuang_saveAs($json)
{
	$ret = array() ;
	$id 			= get_jsonValue($json,"id") ;
	if (sql_check("select `sid` from `taozhuang` where `sid` = '$id'") == false){
		$ret['result'] = 0 ;
		$ret['memo'] = "没有找到此套装" ;
		return $ret ;
	}
	
	$one = sql_fetch_one("select * from `taozhuang` where `sid` = '$id'") ;
	$newid = sql_insert("INSERT INTO `taozhuang` (`name`, `tips`,`pos_type`,`price_base`,`price_custom`,`app_return`,`img_small_id`,`img_thumb_id`,`img_url_id`) VALUES ('{$one['name']} 副本','{$one['tips']}', '{$one['pos_type']}', '{$one['price_base']}', '{$one['price_custom']}', '{$one['app_return']}', '0', '0', '0')") ;
	$onelist = sql_fetch_rows("select * from `taozhuang_pos` where `tzid` = '$id'") ;
	foreach ($onelist as $o){
		$posnewid = sql_insert("INSERT INTO `taozhuang_pos` (`tzid`, `img_id`,`pos`,`order`,`x`,`y`,`father`,`anchor_x`,`anchor_y`,`rotate`,`zoom`,`mirror`) VALUES ('$newid','{$o['img_id']}', '{$o['pos']}' ,'{$o['order']}','{$o['x']}','{$o['y']}','{$o['father']}','{$o['anchor_x']}','{$o['anchor_y']}','{$o['rotate']}','{$o['zoom']}','{$o['mirror']}')") ;
		test_taozhuang_id_item_id_dy($posnewid , $o['img_id']) ;
	}
	
	$ret = array() ;
	$ret['result'] = 1 ;
	$ret['newid'] = $newid ;
	$ret['tzList'] = sql_fetch_rows("select * from taozhuang") ;
	return $ret ;
}
/**
 * 某个套装编辑另存为默认
 */
function test_taozhuang_saveDefault($json)
{
	$ret = array() ;
	$tzid 			= get_jsonValue($json,"id") ;
	if (sql_check("select `sid` from `taozhuang` where `sid` = '$tzid'") == false){
		$ret['result'] = 0 ;
		$ret['memo'] = "没有找到此套装" ;
		return $ret ;
	}
	$def_ids = get_jsonValue($json,"arr") ;
	foreach ($def_ids as $d)
	{
		$defid = get_jsonValue($d , 'id') ;
		$defpos = get_jsonValue($d , 'pos') ;
		$defimg = get_jsonValue($d , 'img_id') ;
		$addset = "" ;
		if (intval($defimg) > 0){
			$addset = " , `img_id` = '$defimg' " ;
		}
		$order = sql_fetch_one_cell("select `order` from `taozhuang_pos` where `id` = '$defid'") ;
		if (intval($order) != 0){
			sql_query("update `taozhuang_pos` set `order` = '-1' where `id` = '$defid'") ;
			sql_query("update `taozhuang_pos` set `order` = '$order' where `tzid` = '$tzid' and `pos` = '$defpos' and `order` = 0") ;
			sql_query("update `taozhuang_pos` set `order` = '0' $addset where `id` = '$defid'") ;
		}else{
			if (intval($defimg) > 0){		
				sql_query("update `taozhuang_pos` set `img_id` = '$defimg' where `id` = '$defid'") ;
			}
		}
	}
	
	$ret = array() ;
	$ret['result'] = 1 ;
	$ret['tz'] = sql_fetch_rows("select `sid`,`name`,`tips`,`pos_type` from taozhuang where `sid` = $tzid");
	$ret['tz_pos'] = test_get_tz_pos_for_where("`tzid` = $tzid and `order` = 0") ;
	return $ret;	
}

/**
 *  添加一个新的套装
 */
function test_add_taozhuang($json)
{
	$nm = get_jsonValue($json,"name") ;
	$ty = get_jsonValue($json,"type") ;
	$tips = get_jsonValue($json,"tips") ;
	$price_base = get_jsonValue($json,"price_base") ;
	$price_custom = get_jsonValue($json,"price_custom") ;
	$package_price = get_jsonValue($json,"package_price") ;
	$app_return =  get_jsonValue($json,"app_return") ;
	$space_id =  get_jsonValue($json,"space_id") ;
	$tc_b_id = get_jsonValue($json,"tc_b_id") ;
	$price_memo = get_jsonValue($json,"price_memo") ;
	
	$new_id = sql_insert("INSERT INTO `taozhuang` (`name`, `tips`,`pos_type`,`price_base`,`price_custom`,`app_return`,`space_id`,`state_tree`,`package_price`,`price_memo`) VALUES ('$nm','$tips', '$ty', '$price_base', '$price_custom', '$app_return','$space_id','$tc_b_id','$package_price','$price_memo')") ;
	$style_arr = get_jsonValue($json,"style_arr") ;
	foreach ($style_arr as $sy){
		sql_insert("INSERT INTO `taozhuang_style` (`taozhuang_id` , `style_id`) values ('$new_id' , '$sy') ON DUPLICATE KEY UPDATE `style_id` = '$sy'") ;
	}
	$color_arr = get_jsonValue($json,"color_arr") ;
	foreach ($color_arr as $sy){
		sql_insert("INSERT INTO `taozhuang_color` (`taozhuang_id` , `color_id`) values ('$new_id' , '$sy') ON DUPLICATE KEY UPDATE `color_id` = '$sy'") ;
	}
	
	$offset = get_jsonValue($json,"offset") ;
	$limit  = get_jsonValue($json,"limit") ;
	$filter_name = trim(get_jsonValue($json,"filter_name")) ;
	$test = new test_bk() ;
	$ret = $test->get_table_for_page($offset , $limit , true , $filter_name , "taozhuang") ;
	
	$ret['tzList'] = sql_fetch_rows("select * from taozhuang") ;
	return $ret;
}

/**
 * 套装基本信息的更新
 */
function test_edit_taozhuang($json)
{
	$sid = get_jsonValue($json,"sid") ;
	$nm = get_jsonValue($json,"name") ;
	$ty = get_jsonValue($json,"type") ;
	$tips = get_jsonValue($json,"tips") ;
	$price_base = get_jsonValue($json,"price_base") ;
	$price_custom = get_jsonValue($json,"price_custom") ;
	$package_price = get_jsonValue($json,"package_price") ;
	$app_return =  get_jsonValue($json,"app_return") ;
	$space_id =  get_jsonValue($json,"space_id") ;
	$tc_b_id = get_jsonValue($json,"tc_b_id") ;
	$price_memo = get_jsonValue($json,"price_memo") ;
	
	sql_query("update `taozhuang` set `name` = '$nm', `tips` = '$tips',`pos_type` = '$ty' , `price_base` = '$price_base' , `price_custom` = '$price_custom' , `package_price` = '$package_price' , `app_return` = '$app_return' , `space_id` = '$space_id' , `state_tree` = '$tc_b_id' , `price_memo` = '$price_memo' where `sid` = '$sid'") ;
	sql_query("delete from `taozhuang_style` where `taozhuang_id` = '$sid'") ;
	sql_query("delete from `taozhuang_color` where `taozhuang_id` = '$sid'") ;
	
	$style_arr = get_jsonValue($json,"style_arr") ;
	foreach ($style_arr as $sy){
		sql_insert("INSERT INTO `taozhuang_style` (`taozhuang_id` , `style_id`) values ('$sid' , '$sy') ON DUPLICATE KEY UPDATE `style_id` = '$sy'") ;
	}
	$color_arr = get_jsonValue($json,"color_arr") ;
	foreach ($color_arr as $sy){
		sql_insert("INSERT INTO `taozhuang_color` (`taozhuang_id` , `color_id`) values ('$sid' , '$sy') ON DUPLICATE KEY UPDATE `color_id` = '$sy'") ;
	}

	if (intval($app_return) == 2){
	    // 套装下架 - 某个套装下架时，同时删除build_type表中tz_img_list对应的套装id。
        $bu_ty = sql_fetch_rows("select * from build_type") ;
        foreach ($bu_ty as $bu){
            $tzlist = $bu['tz_img_list'] ;
            $as = explode(",",$tzlist) ;
            if (count($as) > 0) {
                for ($i = 0; $i <= count($as); ++$i) {
                    if (intval($as[$i]) == intval($sid)) {
                        $as[$i] = 0;
                    }
                }
                $newtzlist = array_to_strings_no_0($as);
                $buid = $bu['id'] ;
                sql_query("update `build_type` set `tz_img_list` = '$newtzlist' where `id` = '$buid'") ;
            }
        }
    }

	$offset = get_jsonValue($json,"offset") ;
	$limit  = get_jsonValue($json,"limit") ;
	$filter_name = trim(get_jsonValue($json,"filter_name")) ;
	$test = new test_bk() ;
	$ret = $test->get_table_for_page($offset , $limit , false , $filter_name , "taozhuang") ;
	
	$ret['tzList'] = sql_fetch_rows("select * from taozhuang") ;
	return $ret;
}

/**
 *  获取套装额外的过滤分类属性
 */
function test_taozhuang_exparam($json)
{
	$tzid = get_jsonValue($json,"tzid") ;
	$ret = array() ;
	$ret['color'] = sql_fetch_rows("select * from taozhuang_color where taozhuang_id = '$tzid'") ;
	$ret['style'] = sql_fetch_rows("select * from taozhuang_style where taozhuang_id = '$tzid'") ;
	return $ret ;
}

/**
 *  更换套装某位置绑定指向的单品id
 */
function test_taozhuang_changeItem_id($json)
{
	$id = get_jsonValue($json,"id") ;
	$itemid = get_jsonValue($json,"item_id") ;
	sql_query("update `taozhuang_pos` set `item_id` = '$itemid' where `id` = '$id'") ;
	
	$ret = array() ;
	$ret['item_id'] = sql_fetch_one_cell("select item_id from taozhuang_pos where `id` = '$id'") ; 
	return $ret ;
}


/**
 * 在套装中某位置插入新的商品
 */
function test_insertNewPos($json)
{
	$tzid = get_jsonValue($json,"id") ;
	$itemid = get_jsonValue($json,"itemid") ;
		
	$maxpos = intval(sql_fetch_one_cell("select max(`pos`) from taozhuang_pos where `tzid` = '$tzid'")) ;
	$maxpos += 100 ;
		
	if (test_check_image_in_itemPreview($itemid) == false){
		$ret = array() ;
		$ret['status'] = -1 ;
		$ret['message'] = "此透视图单品中不存在" ;
		return $ret ;
	}
		
	$newid = sql_insert("INSERT INTO `taozhuang_pos` (`tzid`, `img_id`,`pos`,`x`,`y`) VALUES ('$tzid','$itemid', '$maxpos','200','200')") ;		
	test_taozhuang_id_item_id_dy($newid , $itemid) ;	
	
	$ret = array() ;
	$ret['tz_one'] = test_get_tz_one_for_where("`id` = $newid") ; 
	return $ret ;	
}
/**
 *  删除选中的套装中的商品
 */
function test_delSelPos($json)
{
	$id = get_jsonValue($json,"id") ;
		
	$sel = sql_fetch_one("select * from taozhuang_pos where `id` = '$id'") ;		
	$pos = intval($sel['pos']) ;
	$tzid = intval($sel['tzid']) ;
	sql_query("delete from taozhuang_pos where `id` = '$id'") ;
	if (intval($sel['order']) == 0){
		sql_query("delete from taozhuang_pos where `tzid` = '$tzid' and `father` = '$pos'") ;
	}
	$all = sql_fetch_rows("select * from taozhuang_pos where `tzid` = '$tzid' and `pos` = '$pos' order by `order` asc") ;
	sql_query("update taozhuang_pos set `order` = `order` * 100 where `tzid` = '$tzid' and `pos` = '$pos'") ;
	$order = 0 ;
	foreach ($all as $a){
		sql_query("update taozhuang_pos set `order` = '$order' where `id` = {$a['id']}") ;
		$order = $order + 1 ;
	}
		
	$ret = array() ;
	$ret['tz'] = sql_fetch_rows("select `sid`,`name`,`tips`,`pos_type` from taozhuang where `sid` = $tzid");
	$ret['tz_pos'] = test_get_tz_pos_for_where("`tzid` = $tzid and `order` = 0") ; 
	return $ret ;		
}
/**
 *  插入一个可以(换装)的套装中某个商品
 */
function test_insertChildPos($json)
{
	$tzid = get_jsonValue($json,"id") ;
	$itemid = get_jsonValue($json,"itemid") ;	// 图片id
	$pos = get_jsonValue($json,"pos") ;
			
	if (test_check_image_in_itemPreview($itemid) == false){
		$ret = array() ;
		$ret['status'] = -1 ;
		$ret['message'] = "此透视图单品中不存在" ;
		return $ret ;
	}		
			
	$maxorder = intval(sql_fetch_one_cell("select max(`order`) from taozhuang_pos where `tzid` = '$tzid' and `pos` = '$pos'")) ;
	$maxorder += 1 ;
	
	$item = sql_fetch_one("select * from taozhuang_pos where `tzid` = '$tzid' and `pos` = '$pos' and `order` = 0");
	$x 			= $item['x'] ;
	$y 			= $item['y'] ;
	$f 			= $item['father'] ;
	$anchor_x 	= $item['anchor_x'] ;
	$anchor_y 	= $item['anchor_y'] ;
	$rotate 	= $item['rotate'] ;
	$zoom 		= $item['zoom'] ;
	$mirror 	= $item['mirror'] ;
	
	$newid = sql_insert("INSERT INTO `taozhuang_pos` (`tzid`, `img_id`,`pos`,`order`,`x`,`y`,`father`,`anchor_x`,`anchor_y`,`rotate`,`zoom`,`mirror`) VALUES ('$tzid','$itemid', '$pos' ,'$maxorder','$x','$y','$f','$anchor_x','$anchor_y','$rotate','$zoom','$mirror')") ;
	test_taozhuang_id_item_id_dy($newid , $itemid) ;	
	
	$ret = array() ;
	$ret['tz_one'] = test_get_tz_one_for_where("`id` = '$newid'") ; 
	return $ret;
}
/**
 * 检查套装透视图是否已经编辑到单品中了,如果是,绑定此单品到套装位置中.
 *
 * @param pos表中新的商品id
 * @param 商品套装使用的透视图id
 */
function test_taozhuang_id_item_id_dy($newid , $img_id)
{
	$img = sql_fetch_one("select * from sys_image where `id` = '$img_id'") ;
	$one = sql_fetch_one("select * from `base_sys_preview` where `img_tz_id` = '$img_id'") ;
	if (is_null($one) || array_key_exists('item_id' , $one) == false){
		$itid = sql_insert("insert into `sys_item`(`type` , `name` , `img_small_id` , `img_thumb_id` , `img_url_id` , `app_return`) values ('{$img['type']}' , '{$img['name']}' , '{$img['id']}' , '{$img['id']}' , '{$img['id']}' , '0')") ;
	}else{
		$itid = $one['item_id'] ;
	}
	sql_query("update `taozhuang_pos` set `item_id` = '$itid' where `id` = '$newid'") ;		
}
/**
 * 检测某图片是否存在单品透视图中.
 */
function test_check_image_in_itemPreview($img_id)
{
	$img = sql_fetch_one("select * from sys_image where `id` = '$img_id'") ;
	$one = sql_fetch_one("select * from `base_sys_preview` where `img_tz_id` = '$img_id'") ;
	if (is_null($one) || array_key_exists('item_id' , $one) == false){
		return false ;
	}else{
		return true ;
	}
}
/**
 *  获取所有套装记录
 */
function test_taozhuang()
{
	$ret = array() ;
	$ret['tzList'] = sql_fetch_rows("select * from taozhuang order by `top_time` desc") ;
	return $ret ;	
}

/**
 *  获取套装信息--分页
 */
function test_taozhuang_page($json)
{
	$pagination = get_jsonValue($json,"pagination") ;
	$offset = get_jsonValue($pagination,"offset") ;
	$limit  = get_jsonValue($pagination,"limit") ;
	$filter_name = trim(get_jsonValue($pagination,"filter_name")) ;
	$test = new test_bk() ;
	$ret = $test->get_table_for_page($offset , $limit , false , $filter_name , "taozhuang") ;
	return $ret ;
}


/**
 * 删除一个套装记录 , 位置什么的都删除了.
 */
function test_delete_from_taozhuang($json)
{
	$id 			= get_jsonValue($json,"id") ;
	if (sql_check("select `sid` from `taozhuang` where `sid` = '$id'")){
		sql_query("delete from `taozhuang` where `sid` = '$id'") ;
		sql_query("delete from `taozhuang_pos` where `tzid` = '$id'") ;
	}
	$ret = array() ;
	$ret['result'] = sql_check("select `sid` from `taozhuang` where `sid` = '$id'") ? 0 : 1 ;
	$ret['del_id'] = $id ;
	return $ret ;
}

/**
 * 获取一组套装信息,包括名字图片,地址等.
 */
function test_get_tz_pos_for_where($where)
{
	$result = sql_fetch_rows("select * from taozhuang_pos where $where order by `pos` asc");
	$test = new test_bk() ;
	foreach ($result as &$t){
		$val = $test->get_taozhuang_pos_for_ts_image($t['id']) ;
		$t['img_id'] = $val[0] ;
		$t['url'] = $val[1] ;
		$t['type'] = $val[2] ;
		$t['name'] = ($t['show_name'] == "")?$val[3]:$t['show_name'] ;
	}
	return $result ;	
}
/**
 * 获取一个套装信息,包括名字图片,地址等.
 */
function test_get_tz_one_for_where($where)
{
	$result = sql_fetch_one("select * from taozhuang_pos where $where");
	$test = new test_bk() ;
	$val = $test->get_taozhuang_pos_for_ts_image($result['id']) ;
	$result['img_id'] = $val[0] ;
	$result['url'] = $val[1] ;
	$result['type'] = $val[2] ;
	$result['name'] = $result['show_name']?$val[3]:$result['show_name'] ;
	return $result ;
}
/**
 *  通过套装 ID 获取套装列表
 */
function test_getTZForID($json)
{
	$tzid = intval(get_jsonValue($json , "id")) ;
	
	$ret = array() ;
	$ret['tz'] = sql_fetch_rows("select * from taozhuang where `sid` = $tzid");
	$ret['tz_pos'] = test_get_tz_pos_for_where("`tzid` = $tzid and `order` = 0") ; 
	$ret['img_bk'] = array() ;
	
	if (count($ret['tz']) >= 1){
		if (intval($ret['tz'][0]['back_img']) > 0){
			util_set_IMAGE_one($ret['img_bk'] , intval($ret['tz'][0]['back_img'])) ;
		}
	}	
	return $ret ;	
}
/**
 *  通过套装 ID 获取所有套装位置列表
 */
function test_getTZForID_AllPos($json)
{
	$tzid = intval(get_jsonValue($json , "id")) ;
	
	$ret = array() ;
	$ret['tz_pos'] = test_get_tz_pos_for_where("`tzid` = $tzid ") ; 
	return $ret ;
}
/**
 *  获取套装pos表中某个记录对应的单品详细信息
 */
function test_getTZ_for_POS_ITEM($json)
{
	$item_id = intval(get_jsonValue($json , "id")) ;
	$posid = get_jsonValue($json , "posid") ;	
	
	$ret = array() ;
	$ret['preview'] = array() ;
	
	if ($item_id == 0 || $posid == 0){
		return $ret ;
	}

	$test = new test_bk() ;
	$default = $test->get_taozhuang_pos_for_ts_image($posid) ;
	$defaultimg = $default[0] ;
	$defaultpos = sql_fetch_one_cell("select `pos` from taozhuang_pos where `id` = '$posid'") ;
	
	$item = sql_fetch_one("select * from `sys_item` where `id` = '$item_id'") ;
	$vals = sql_fetch_array("select p.* , f.`name` as f_name , m.`name` as m_name from base_sys_preview p left join base_sys_fabric f on p.fid = f.id left join base_sys_material m on p.mid = m.id where `item_id` = '$item_id'" , "id") ;	

	foreach ($vals as $v)
	{
		$a = array() ;
		util_set_ITEM_PREVIEW($a , $v , $item) ;
		$a['id'] = $v['id'] ;
		$a['img_tz_id'] = $v['img_tz_id'] ;
		$a['pos'] = $defaultpos ;
		$a['f_name'] = is_null($v['f_name'])?"":$v['f_name'] ;
		$a['m_name'] = is_null($v['m_name'])?"":$v['m_name'] ;
		$a['is_default'] = ($v['img_tz_id'] == $defaultimg) ? 1 : 0 ;
		$ret['preview'][] = $a ;
	}
	if (count($ret['preview']) == 0){
		$a = array() ;
		$a['id'] = $item_id ;
		$a['img_tz_id'] = $defaultimg ;
		$a['pos'] = $defaultpos ;
		$a['f_name'] = "" ;
		$a['m_name'] = "" ;
		$a['is_default'] = 1 ;

		$a['set_image'] = array() ;
		$a['fabric'] 	= "未设置单品透视图" ;
		$a['material'] 	= "" ;
		
		util_set_IMAGE_one($a['set_image'] , $defaultimg) ;
		$ret['preview'][] = $a ;
	}
	
	return $ret ;
}


function test_taozhuang_set_bakimg($json)
{
	$tzid = intval(get_jsonValue($json , "tzid")) ;
	$bkimg= intval(get_jsonValue($json , "imgid")) ;
	
	sql_query("update `taozhuang` set `back_img` = '$bkimg' where `sid` = '$tzid'") ;		
	
	$ret = array() ;
	
	$newid = intval(sql_fetch_one_cell("select `back_img` from `taozhuang` where `sid` = '$tzid'")) ;
	
	if ($newid == $bkimg){
		$ret['result'] = 1 ;
		$ret['imgid'] = $bkimg ;
		$ret['message'] = "套装底图更新成功" ;
	}else{
		$ret['result'] = -1 ;
		$ret['message'] = "更改错误,请联系管理员" ;
	}
	
	return $ret ;
}

?>